﻿<%@ page language="java" import="com.newcrm.config.Const,com.newcrm.config.Config,com.newcrm.util.Util,com.newcrm.bean.*,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  String customerType = request.getParameter("customerType");
  User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<User> users = companyInfo.users;
  List<Group> allGroups = companyInfo.getAllGroups();
  boolean isPeople = "people".equals(customerType);

  Config typeConfig = Config.getInstance();

  // 根据电话来创建公司
  String phone = request.getParameter("phone");
  if (phone == null) {
    phone = "";
  }
%>
<div class="secondary_fields">
  <table class="contact_types" cellpadding="0" cellspacing="0" id="contact_section">
  <tr>
  <th><h2>联系电话</h2></th>
  <td>
    <div class="contact_forms">
      <div class='blank_slate' id="customer_phone_title">填写联系电话</div>
      <div class="contact_methods" id="customer_phone_container" style="display:none;">
        <div id="phone_show">
          <div class="contact_method">
            <input class="autofocus" name="phone" id="customer_phone" value="<%=Util.HTMLEncode(phone)%>" size="30" type="text" value="" />
            <select name="phoneType">
<%for (String type:typeConfig.phoneType) {%>
              <option value="<%=type%>"><%=type%></option>
<%}%>
            </select>
            <a title="删除" href="#" class="remove"><i class="fa fa-times"></i></a>
            </div>
          </div>
          <div class="add_contact_method"><div class="add"><a href="phone_show"><i class="fa fa-plus"></i> 再添加一个</a></div></div>
        </div>
      </div>
    </td>
  </tr>
  <tr>
    <th><h2>邮箱</h2></th>
    <td><div class="contact_forms">
      <div class='blank_slate'>填写联系邮箱</div>
      <div class="contact_methods" style="display:none;">
        <div id="email_show">
          <div class="contact_method">
          <input class="autofocus" name="email" size="30" type="text" />
          <select name="emailType">
<%for (String type:typeConfig.emailType) {%>
            <option value="<%=type%>"><%=type%></option>
<%}%>
          </select>
          <a title="删除" href="#" class="remove"><i class="fa fa-times"></i></a>
          </div>
        </div>
        <div class="add_contact_method">
          <div class="add"><a href="email_show"><i class="fa fa-plus"></i> 再添加一个</a></div>
        </div>
      </div></div>
    </td>
  </tr>
  <tr>
    <th><h2>聊天工具</h2></th>
    <td><div class="contact_forms instant_messengers">
      <div class='blank_slate'>填写QQ，旺旺等聊天帐号</div>
      <div class="contact_methods" style="display:none;">
        <div id="im_show">
          <div class="contact_method">
          <input class="autofocus" name="im" size="30" type="text" value="" />&nbsp;
          <select name="imType1">
<%for (String type:typeConfig.imType) {%>
            <option value="<%=type%>"><%=type%></option>
<%}%>
          </select>
          <select name="imType">
            <option value="工作">工作</option>
            <option value="个人">个人</option>
            <option value="其他">其他</option></select>
          <a title="删除" href="#" class="remove"><i class="fa fa-times"></i></a>
          </div>
        </div>
        <div class="add_contact_method">
          <div class="add"><a href="im_show"><i class="fa fa-plus"></i> 再添加一个</a></div>
        </div>
      </div></div>
    </td>
  </tr>
  <% if (isPeople) { %>
  <tr>
    <th><h2>微博</h2></th>
    <td><div class="contact_forms twitter_accounts">
      <div class='blank_slate'>填写微博帐号</div>
      <div class="contact_methods" style="display:none;">
        <div id="weibo_show">
          <div class="contact_method">
          <input class="autofocus" name="weibo" size="30" type="text" value="" />
          <select name="weiboType">
<%for (String type:typeConfig.weiboType) {%>
            <option value="<%=type%>"><%=type%></option>
<%}%>
          </select>
          <a title="删除" href="#" class="remove"><i class="fa fa-times"></i></a>
          </div>
        </div>
        <div class="add_contact_method">
          <div class="add"><a href="weibo_show"><i class="fa fa-plus"></i> 再添加一个</a></div>
        </div>
      </div></div>
    </td>
  </tr>
  <%}%>
  <tr>
    <th><h2>网站</h2></th>
    <td><div class="contact_forms web_addresses">
      <div class='blank_slate'>填写网址</div>
      <div class="contact_methods" style="display:none;">
        <div id="website_show">
          <div class="contact_method">
          <input class="autofocus" name="website" size="30" type="text" value="" />
          <select name="websiteType">
<%for (String type:typeConfig.websiteType) {%>
            <option value="<%=type%>"><%=type%></option>
<%}%>
          </select>
          <a title="删除" href="#" class="remove"><i class="fa fa-times"></i></a>
          </div>
        </div>
        <div class="add_contact_method">
          <div class="add"><a href="website_show"><i class="fa fa-plus"></i> 再添加一个</a></div>
        </div>
      </div></div>
    </td>
  </tr>
  <tr>
    <th><h2>地址</h2></th>
    <td><div class="contact_forms addresses">
      <div class='blank_slate'>填写联系地址</div>
      <div class="contact_methods" style="display:none;">
        <div id="addresses_show">
          <div class="contact_method address">
            <textarea class="autofocus" id="address" name="address" title="地址"></textarea>
            <p>
              <select name="province" class="province" onchange="changeProvince($(this), false);">
              <option value="">省份</option><option value="安徽">安徽</option><option value="北京">北京</option><option value="福建">福建</option><option value="甘肃">甘肃</option><option value="广东">广东</option><option value="广西">广西</option><option value="贵州">贵州</option><option value="海南">海南</option><option value="河北">河北</option><option value="河南">河南</option><option value="黑龙江">黑龙江</option><option value="湖北">湖北</option><option value="湖南">湖南</option><option value="吉林">吉林</option><option value="江苏">江苏</option><option value="江西">江西</option><option value="辽宁">辽宁</option><option value="内蒙古自治区">内蒙古</option><option value="宁夏回族自治区">宁夏</option><option value="青海">青海</option><option value="山东">山东</option><option value="山西">山西</option><option value="陕西">陕西</option><option value="上海">上海</option><option value="四川">四川</option><option value="天津">天津</option><option value="西藏自治区">西藏</option><option value="新疆维吾尔自治区">新疆</option><option value="云南">云南</option><option value="浙江">浙江</option><option value="重庆">重庆</option><option value="中国香港">香港</option><option value="中国台湾">台湾</option><option value="中国澳门">澳门</option>
              </select>
              <select name="city"><option value="">城市</option></select>
            </p>
            <div class="loc_remove">
              <select name="addressType">
<%for (String type:typeConfig.addressType) {%>
            <option value="<%=type%>"><%=type%></option>
<%}%>
              </select>
              <a title="删除" href="#" class="remove"><i class="fa fa-times"></i></a>
            </div>
          </div>
        </div>
      <div class="add_contact_method">
        <div class="add"><a href="addresses_show"><i class="fa fa-plus"></i> 再添加一个</a></div>
      </div>
      </div></div></td>
  </tr>
  </table>
</div>
<div class="custom_fields">
  <div class="custom_fields_header">
    <h1><a href="#" id="custom_fields_link" title="点击可以展开/缩起自定义信息"><i class="fa fa-plus"></i> 自定义信息</a> </h1>
    <% if (user.isAdmin) {%>
    <a href="<%=request.getContextPath()%>/customerfield" class="link_to"><i class="fa fa-cog"></i> 设置自定义信息</a>
    <% }%>
  </div>
<%List<Map<String, Object>> fields = (List<Map<String, Object>>) request.getAttribute("fields");
  if (fields != null) {%>
  <table id="custom_fields_table" cellpadding="0" cellspacing="0"><%
    for (Map<String, Object> field:fields) {
      int extInfoId = Util.str2Int(field.get("CustomerFieldId"));
      int fieldType = Util.str2Int(field.get("FieldType"));
      int valueType = Util.str2Int(field.get("ValueType"));
      String initValue = (String) field.get("InitValue");
%>
    <tr>
      <th><span><%=Util.HTMLEncode((String)field.get("CustomerFieldName"))%></span></th>
      <td >
       <input name="<%=Const.FIELDID_KEY%>_<%=extInfoId%>" type="hidden" value="0" />
       <%if (valueType == Const.FIELD_TYPE_DATE) {%>
       <input class="datepickerinput" name="<%=Const.FIELD_KEY%>_<%=field.get("CustomerFieldId")%>" size="30" type="text" />
       <%} else if (valueType == Const.FIELD_TYPE_SELECT) {%>
       <select name="<%=Const.FIELD_KEY%>_<%=field.get("CustomerFieldId")%>">
        <option value="">请选择</option>
       <%
        if (initValue != null && initValue.length() > 0) {
          String[] arr = initValue.split(",");
          for (String v:arr) { %>
        <option value="<%=Util.HTMLEncode(v)%>"><%=Util.HTMLEncode(v)%></option>
       <%  }
        }%>
       </select>
       <%} else if (valueType == Const.FIELD_TYPE_CHECKBOX) {
          if (initValue != null && initValue.length() > 0) {
            String[] arr = initValue.split(",");
            for (String v:arr) { %>
          <label><input type="checkbox" name="<%=Const.FIELD_KEY%>_<%=field.get("CustomerFieldId")%>" value="<%=Util.HTMLEncode(v)%>"> <%=Util.HTMLEncode(v)%></label>
       <%   }
          }
        } else if (valueType == Const.FIELD_TYPE_NUMBER) { %>
      <input class="ime-disabled" name="<%=Const.FIELD_KEY%>_<%=field.get("CustomerFieldId")%>" id="<%=Const.FIELD_KEY%>_<%=field.get("CustomerFieldId")%>_number" size="30" type="text" />
      <script>
        $('#<%=Const.FIELD_KEY%>_<%=field.get("CustomerFieldId")%>_number').bind('keypress', function(e) {
          return ( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) ? false : true;
        });
      </script>
      <%} else {%>
      <input name="<%=Const.FIELD_KEY%>_<%=field.get("CustomerFieldId")%>" size="30" type="text" />
       <%}%>
      </td>
    </tr>
<%
    }
%>
  </table>
<%
  }
%>
</div>

<div class="contact_forms background">
  <div class="contact_methods">
    <div class="contact_method">
      <p class="background_label"><strong>简介</strong> (介绍，如何认识的等)</p>
      <textarea cols="40" id="background" name="background" rows="20"></textarea>
    </div>
  </div>
</div>

<%
String companyId = request.getParameter("companyId");
if (companyId == null || companyId.length() == 0) {
%>
<div class="permissions">
  <h5>权限设置</h5>
  <div class="form_section">
    <div class="select_permissions">
      <div class="scope">
        <label><input name="visible" value="<%=Const.VISIBLE_EVERYONE%>" type="radio"/> 公海</label>
        <select name="groupPermissionsId" id="groupPermissionsId">
          <jsp:include page="commonPublicDataSelection.jsp" flush="true"/>
        </select>
      </div>
      <div class="scope">
        <label><input name="visible" value="<%=Const.VISIBLE_PERSON%>" checked type="radio"/> 私有数据 </label>
        <div class="editor">
          <select name="permissionsId" id="permissionsId">
            <jsp:include page="commonUserSelection.jsp" flush="true"/>
          </select>
          <div class="shareUsers">
            <p><b>同时，共享给如下的同事</b></p>
            <!--
            <div class="scope">
              <label>部门:</label>
              <div class="editor">
                <% if (allGroups != null) {
                    for (Group group : allGroups) {%>
                <label id="shareGroupId_<%=group.getId()%>"><input name="shareGroupId" type="checkbox" value="<%=group.getId()%>" /> <%=Util.HTMLEncode(group.getName())%></label>
                    <%  }
                } %>
              </div>
            </div>
            -->
            <div id="share_person" class="scope">
              <label>个人:</label>
              <div class="editor">
                <%
                  String groupNameForShare = null;
                  for (User u : users) {
                    if (u.userId.equals(user.userId)) {
                      continue;
                    }
                    String gn = companyInfo.getGroupName(u);
                    if (gn != null && !gn.equals(groupNameForShare)) {
                      groupNameForShare = gn;  %>
                    <p><%=Util.HTMLEncode(groupNameForShare)%></p>
                  <%}%>
                  <label id="shareUserId_<%=u.userId%>"><input name="shareUserId" type="checkbox" value="<%=u.userId%>" /> <%=Util.HTMLEncode(u.name)%></label>
                <%}%>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<%}%>